package pl.tssoft.math.core.parser;

import pl.tssoft.math.core.calculation.operator.OperatorType;

public enum ElementType {

    BEGIN,
    NAME,
    NUMBER,
    OPERATOR_OR_END_OF_EXPRESSION,
    OPERATOR_LEFT_SIDE,
    OPERATOR_LEFT_OR_BOTH_SIDE,
    OPERATOR_BOTH_SIDE,
    OPERATOR_RIGHT_SIDE,
    OPERATOR_END_OF_EXPRESSION,
    SQUARE_BLOCK,
    BRACKET_BLOCK;

    public boolean isOperatorSupportingLeftSide() {
        return this == OPERATOR_LEFT_OR_BOTH_SIDE || this == OPERATOR_LEFT_SIDE;
    }

    public boolean isOperatorSupportingRightSide() {
        return this == OPERATOR_RIGHT_SIDE;
    }

    public boolean isOperatorSupportingBothSide() {
        return this == OPERATOR_LEFT_OR_BOTH_SIDE || this == OPERATOR_BOTH_SIDE;
    }

    public boolean isSquareOrBracketBlock() {
        return this == SQUARE_BLOCK || this == BRACKET_BLOCK;
    }

    public boolean isNameOrNumber() {
        return this == NAME || this == NUMBER;
    }

    public static ElementType valueOf(OperatorType type) {
        switch (type) {
            case LEFT_SIDE:
                return OPERATOR_LEFT_SIDE;
            case LEFT_OR_BOTH_SIDE:
                return OPERATOR_LEFT_OR_BOTH_SIDE;
            case BOTH_SIDE:
                return OPERATOR_BOTH_SIDE;
            case RIGHT_SIDE:
                return OPERATOR_RIGHT_SIDE;
            default:
                throw new AssertionError(type.name());
        }
    }
}
